#include <bits/stdc++.h>

using namespace std;

struct l_node{
    char c;
    l_node* next;
    l_node(char cc):c(cc),next(NULL){}
};
class Solution
{
private:
    unordered_map<char,int> hamp;
    l_node *lt;
public:
    Solution(){
        lt=new l_node('#');
    }

  //Insert one char from stringstream
    void Insert(char ch)
    {
        int val=hamp[ch];

        if(val==0){
            l_node *p=new l_node(ch);
            l_node *q=lt;
            while(q->next){
                q=q->next;
            }
            q->next=p;
        }else if(val==1){
            l_node *q=lt;
            while(q->next){
                if(q->next->c==ch){
                    l_node *p=q->next;
                    q->next=p->next;
                    delete p;
                    break;
                }
                q=q->next;
            }
        }
        hamp[ch]=++val;
    }

  //return the first appearence once char in current stringstream
    char FirstAppearingOnce()
    {
        return lt->next==NULL?'#':lt->next->c;
    }

};

int main(){
    Solution s;

    s.Insert('a');
    cout <<s.FirstAppearingOnce()<<endl;
    s.Insert('a');
     cout <<s.FirstAppearingOnce()<<endl;
    s.Insert('b');
    cout <<s.FirstAppearingOnce()<<endl;
    s.Insert('c');
    s.Insert('b');
    cout <<s.FirstAppearingOnce()<<endl;
    

    return 0;
}